import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
//5.1修改elementPlus默认中文
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'

const BASE_URL = "http://localhost:8080"
window.BASE_URL=BASE_URL



//引入elementplus组件库
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'


// main.ts

// 引入element-plus图标库
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

//遍历ElementPlusIconsVue对象中所有的图标组件并注册到vue实例app中
const app = createApp(App)
app.config.globalProperties.BASE_URL=BASE_URL

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

//use(ElementPlus)  给当前vue实例使用elementplus组件库
app.use(ElementPlus,{ locale: zhCn }).use(store).use(router).mount('#app')
//6.解决ResizeObserver Error
const debounce = (fn, delay) => {
    let timer = null;
    return function () {
        let context = this;
        let args = arguments;
        clearTimeout(timer);
        timer = setTimeout(function () {
            fn.apply(context, args);
        }, delay);
    }
}
const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
    constructor(callback) {
        callback = debounce(callback, 16);
        super(callback);
    }
}

// 定义获取当前登录人数据的全局方法
window.getUser=()=>{
    return localStorage.user?JSON.parse(localStorage.user):null
}

// 定义根据路由获取对应面包屑路径
/*
window.getbre=()=>{
    let href=window.location.href
    switch (href.slice(href.lastIndexOf("/"))){
        case "/user": return "/user"
        case "/vehicle": return "/vehicle"
        case "/geofence": return "/geofence"
        case "/application": return "/application"
        case "/audit": return "/audit"
        case "/distribute": return "/distribute"
        case "/dict": return "/dict"
    }
}*/
